﻿using System.IO;
using System.Xml;

namespace FileWatcher.Action
{
    public class CopyAction : ActionBase
    {
        private string m_destination;

        public override string Name
        {
            get { return "Copy"; }
        }

        public string Destination
        {
            get { return this.m_destination; }
        }

        public CopyAction(bool delete)
            : base(delete)
        {
            System.Windows.Forms.FolderBrowserDialog browser = new System.Windows.Forms.FolderBrowserDialog();
            browser.RootFolder = System.Environment.SpecialFolder.MyComputer;
            browser.ShowNewFolderButton = true;

            if (browser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.m_destination = browser.SelectedPath;
            }
        }

        public CopyAction(bool delete, string folder)
            : base(delete)
        {
            this.m_destination = folder;
        }

        protected override void Action(Node node)
        {
            File.Copy(node.Location, m_destination + node.Location.Substring(node.Location.LastIndexOf("\\")), true);
        }
    }
}